package com.spring.cloudeurekaserver.config

import com.netflix.discovery.EurekaClientConfig
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.AutoConfigureBefore
import org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration
import org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean
import org.springframework.context.annotation.Configuration

@Configuration
@AutoConfigureBefore(EurekaServerAutoConfiguration.class)   //执行在某些自动配置之前的配置
class EurekaConfig {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    EurekaConfig(EurekaClientConfig clientConfig, EurekaServerConfigBean serverConfig){
        if (clientConfig.shouldRegisterWithEureka())
                serverConfig.registrySyncRetries=5
        //由于EurekaServerConfigBean中的remoteRegionAppWhitelist属性默认为null,所以getRemoteRegionAppWhitelist会抛出空指针异常
        serverConfig.remoteRegionAppWhitelist = new HashMap<>()
  }

}
